Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Backend Architecture for the AasRepository and AasService #570

Merged

Conversation

mateusmolina-iese
Copy link
Member

@mateusmolina-iese mateusmolina-iese commented Dec 10, 2024

Supersedes #555

Linked to 1st Phase of #584

  1. AasRepositoryBackend is an interface for which Spring automatically generates a Bean based on the available CrudRepositories.
  2. AasRepositoryBackend extends the interface AasServiceOperations. Spring injects AasServiceOperations as a Repository Fragment, aligning with the recommended approach for achieving native Spring composition.
  3. AasServiceOperations serves as a reusable interface for both AasRepositoryBackend and AasService:
    • In AasRepositoryBackend, it is provided by Spring as a composable Fragment.
    • In AasService, it is injected as a dependency.
  4. By default, Spring searches for an implementation named AasServiceOperationsImpl within the same package as the interface. However, this approach does not align with the current architecture, which distributes backend implementations across different packages and modules.
    1. To address this, AasRepositoryFragmentConfiguration is introduced to manage custom injection of AasServiceOperations. If a Bean named aasServiceOperations is available, it is automatically composed into AasRepositoryBackend. This ensures that the location of the implementation no longer affects its integration.
    2. For example, MongoDbAasServiceOperations (the MongoDB implementation of AasServiceOperations) can reside in the aasservice-backend-mongodb package while being utilized by aasrepository-backend-mongodb by registering a Bean with the expected naming convention. This approach enhances flexibility and control over the overall backend implementation.
  5. Another key design decision was to make AasServiceOperations function more like a @service. Specifically:
    • Exceptions are thrown in a manner consistent with typical service-layer behavior.
    • This contrasts with Spring's CrudRepository, where certain operations—such as failing to find or delete a non-existent entity—are silently ignored.
    • This approach optimizes backend-specific exception handling when AasServiceOperations is used within CrudAasRepository (not to be confused with Spring’s CrudRepository).
    • As a result, there is no need to pre-check an entity’s existence at the service layer before calling AasServiceOperations—the appropriate exception is thrown immediately with minimal database queries.

@mateusmolina-iese mateusmolina-iese changed the title Repositories Consolidation Refactor Backend Architecture Dec 10, 2024
@aaronzi aaronzi mentioned this pull request Jan 10, 2025
1 task
@mateusmolina-iese mateusmolina-iese force-pushed the feat/repositories-consolidation branch from 06f95ce to b659e26 Compare January 30, 2025 13:32
@mateusmolina-iese mateusmolina-iese marked this pull request as ready for review February 3, 2025 14:47
Copy link
Member

@aaronzi aaronzi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR. Implementation wise this looks fine to me. I just added a small suggestion

@mateusmolina-iese mateusmolina-iese changed the title Refactor Backend Architecture Refactor Backend Architecture for the AasRepository and AasService Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants